package com.manolovn.sample.color;

import com.manolovn.colorbrewer.ColorBrewer;
import com.manolovn.trianglify.generator.color.ColorGenerator;

/**
 * Color brewer color generator
 */
public class BrewerColorGenerator implements ColorGenerator {
    private ColorBrewer palette;
    private int index = 0;
    private int[] colors;

    /**
     * BrewerColorGenerator parameterized constructor
     *
     * @param palette refers color palette
     */
    public BrewerColorGenerator(ColorBrewer palette) {
        this.palette = palette;
    }

    /**
     * set number of colors
     *
     * @param count refers to number of colors
     */
    public void setCount(int count) {
        colors = palette.getColorPalette(count);
        index = 0;
    }

    /**
     * will iterate to next color
     */
    @Override
    public int nextColor() {
        int color = colors[index];
        index++;
        return color;
    }
}
